﻿@{
    ViewBag.Title = "FormUpload";
    Layout = "~/Views/Shared/_Layout2.cshtml";
}

<div class="service-detail">
    <div class="service-detail-container">
        <h2>Upload</h2>
        @if (ViewData["issuccess"] != null)
        {
            <div class="alert fade in">
                <button type="button" class="close" data-dismiss="alert">×</button>
                File size : @ViewData["size"]    ;
            </div>
        }
        @using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data", Class = "form-inline", onsubmit = "return validateUpload();", id = "general-upload-file" }))
        {
            <label>Select Your File :</label> <input type="file" name="file" />
            <input type="submit" value="Upload" />
        }
    </div>
</div>
<script>
    function validateUpload() {
        var file = $('#general-upload-file').find('input[name=file]').val();
        if (!file) {
            alert("no file choosen");
            return false;
        }
        var extension = getextension(file);
        var patt = /\.(rar|zip)$/i;
        alert(extension);
        if (patt.test(file)) {
            alert("is rar or zip")
        } else {
            alert("not rar or zip");
            return false;
        }
    }
    function getextension(filename) {
        var a = filename.split('.');
        if (a.length == 1 || (a[0] = "" && a.length == 2)) {
            return "";
        }
        return a.pop();
    }
</script>
